﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WarriorRush.GameDynamics;
using WarriorRush.GameDynamics.Characters;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace WarriorRush.UserInterface
{
    public class DescriptionManager
    {

        public Dictionary<EffectType, Descriptors> Effects;
        public Dictionary<AbilityTypes, Descriptors> Abilities;
        public Dictionary<CharacterTypes, Descriptors> Warriors;
        public Dictionary<RushStage, string> PhaseDescription;
        private TextureManager textureManager;
        public CharacterClass CurrentWarrior;

        public DescriptionManager(TextureManager textures)
        {
            
            textureManager = textures;
            
            Effects = new Dictionary<EffectType, Descriptors> {
                {EffectType.Blinded, new Descriptors("Blinded","Warrior's rush distance is reduced by {0}")},
                {EffectType.Enraged, new Descriptors("Enraged","Warrior's attack power is increased by {0}")},
                {EffectType.Poisoned, new Descriptors("Poisoned","Warrior takes an additional {0} damage from all sources")},
                {EffectType.Shielded, new Descriptors("Shielded","Damage to warrior is  reduced by {0}")},
                {EffectType.Silenced, new Descriptors("Silenced","Warrior loses offensive abilities")},
                {EffectType.Dazed, new Descriptors("Dazed","Warrior's offensive ability reduced by {0}")},
                {EffectType.Haste, new Descriptors("Haste","Warrior's rush range increased by {0}")}

            };

            Abilities = new Dictionary<AbilityTypes, Descriptors>{
                {AbilityTypes.Blind, new Descriptors("Blind","Reduces attack targest rush range")},
                {AbilityTypes.Cleave, new Descriptors("Cleave","Deals {0} damage enemies in front row above and below target")},
                {AbilityTypes.Enrage, new Descriptors("Enrage","Warrior boosts itself with the enrage effect")},
                {AbilityTypes.Evasion, new Descriptors("Evasion","Warrior switches positions with another character {0} squares away.")},
                {AbilityTypes.Heal, new Descriptors("First Aid","Warrior heals friendly units adjacent to the warrior by {0}")},
                {AbilityTypes.Pierce, new Descriptors("Pierce","Warrier deals {0} damage to character behind target")},
                {AbilityTypes.Poison, new Descriptors("Poison","Poisons target")},
                {AbilityTypes.Range, new Descriptors("Range","Deal attack damage to enemy target within {0} squares.\n Rush target still attacks back")},
                {AbilityTypes.Shield, new Descriptors("Shield","Warrior gains shielding")},
                {AbilityTypes.Silence, new Descriptors("Silence","Target loses offensive ability")},
                {AbilityTypes.Patrol, new Descriptors("Patrol","Adjacent friendlies in the front row gain shielding")},
                {AbilityTypes.Daze, new Descriptors("Daze","Target's attack damaage reduced by {0}")},
                {AbilityTypes.HardenSkin, new Descriptors("Harden Skin","Damage dealt to warrior is reduced by {0} \nRush range is also reduced by {0}")},
                {AbilityTypes.Hasten, new Descriptors("Hasten","Rush range increased by {0}")}
            };

            Warriors = new Dictionary<CharacterTypes, Descriptors>{
                {CharacterTypes.Archer, new Descriptors("Archer","Has ranged attack.  Can move after being rushed")},
                {CharacterTypes.Barbarian, new Descriptors("Barbarian","Deals damage to warriors around rush target.\n  Becomes enraged when attacked")},
                {CharacterTypes.Brigand, new Descriptors("Rogue","Blinds target of rush.  Poisons attacker")},
                {CharacterTypes.Infantry, new Descriptors("Infantry","Deals damage to warrior behind rush target. \n  Shields itself after ")},
                {CharacterTypes.Medic, new Descriptors("Medic","Heals friendly warriors next to it on rush. \n  Disables enemy defensively")},
                {CharacterTypes.Commander, new Descriptors("Captain", "Shields friendly units on attack")},
                {CharacterTypes.Gargoyle, new Descriptors("Gargoyle", "Shields itself after attack but limits rush range.\n Rush range increases after defense")}
            };
        }

        public void DrawCurrentWarrior(SpriteBatch spriteBatch)
        {
            if(CurrentWarrior != null)
                DrawCharacter(spriteBatch, CurrentWarrior);
        }

        public void DrawCharacter(SpriteBatch spriteBatch, CharacterClass warrior)
        {

            textureManager.DrawText(spriteBatch, new Vector2(350, 20),
                 Warriors[warrior.Type].Name + "\n"
                    + Warriors[warrior.Type].Description + "\n"
                    + GetStats(warrior.Stats) + "\n"
                    + GetAbilities(warrior) + "\n"
                    + GetEffects(warrior), 
                    1, 
                    Color.Black);
           
        }

        public string GetStats(CharacterStats stats)
        {
            return String.Format(
                   "Stats: Rush Range: {0} Attack: {1} Defense: {2}",
                   stats.RushRange,
                   stats.Attack,
                   stats.Defense
                   );
        }

        public string GetEffects(CharacterClass warrior)
        {
            string boost = "";
            string drain = "";
            if (warrior.Boost.Type != EffectType.Null)
                boost = String.Format("Bosted With: {0}", GetEffectTypeBasics(warrior.Boost)) +  "\n" + GetEffectDescription(warrior.Boost);
            if (warrior.Drain.Type != EffectType.Null)
                drain = String.Format("Drain With: {0}", GetEffectTypeBasics(warrior.Drain)) + "\n" + GetEffectDescription(warrior.Drain);

            return boost + "\n" + drain ;
        }

        public string GetEffectTypeBasics(GameEffect effect)
        {
            return String.Format("{0}({1})", Effects[effect.Type].Name, effect.Power);

        }

        public string GetEffectDescription(GameEffect effect)
        {
            return String.Format(Effects[effect.Type].Description, effect.Power);
        }

        public string GetAbilities(CharacterClass warrior)
        {
            return GetAbilityDescription(warrior.OffensiveAbility) + "\n" + GetAbilityDescription(warrior.DefensiveAbility);
        }

        public string GetAbilityDescription(SpecialAbility ability)
        {
            var abilityDetails = Abilities[ability.AbilityType];
            return String.Format( abilityDetails.Name+ "({0})\n" + abilityDetails.Description, ability.Power) ;
        }

    }
}
